cmake_minimum_required(VERSION 3.15)


if(CMAKE_GENERATOR AND (CMAKE_GENERATOR STREQUAL "MinGW Makefiles"))
    message(STATUS "${CMAKE_GENERATOR}: ")

    if(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
        message("Debug mode")

    elseif(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
        message("Release mode")
        
    else()
        message("else:${CMAKE_BUILD_TYPE}")
        message("else:${CMAKE_CXX_FLAGS_RELEASE}")
    endif()

    message(STATUS "${CMAKE_C_COMPILER}")
    message(STATUS "${CMAKE_BUILD_TYPE}")
endif()

set(CMAKE_CXX_COMPILER g++)

project(
    EffectiveModernC++
    VERSION 0.1.0
    LANGUAGES CXX C
)

# for g++, disable RVO
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-elide-constructors")

add_subdirectory(Chapter1)
add_subdirectory(Chapter2)
add_subdirectory(Chapter3)
# add_subdirectory(Chapter4)
add_subdirectory(Chapter5)
add_subdirectory(Chapter6)

set(CMAKE_CXX_STANDARD 17)